package com.zy.design.state;

/**
 * @author hugx
 * @create 2018-09-12 10:01
 */
public class StateContext {
    protected OpenDoorState openDoorState = new OpenDoorState();
    protected CloseDoorState closeDoorState = new CloseDoorState();
    protected RuningDoorState runingDoorState = new RuningDoorState();
    protected StopDoorState stopDoorState = new StopDoorState();

    private LiftState liftState;

    public StateContext(){
        initState();
    }

    private void initState(){
        setLiftState(stopDoorState);
    }

    protected LiftState getLiftState() {
        return liftState;
    }

    protected void setLiftState(LiftState liftState) {
        this.liftState = liftState;
        this.liftState.setStateConetxt(this); //此句很关键，即把 stateContext 对象注入到具体的状态对象中
    }

    /**
     * 开门
     */
    public void openDoor() {
        liftState.openDoor();
    }

    /**
     * 关电梯门
     */
    public void closeDoor() {
        liftState.closeDoor();
    }

    /**
     * 启动电梯
     */
    public void runing() {
        liftState.runing();
    }


    /**
     * 停止电梯
     */
    public void stop() {
        liftState.stop();
    }

}
